package com.wn.portal.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author yellow Docter
 * @date 2022 -08-22
 * @desc
 */
@RestController
@RequestMapping("/portal")
public class PorTalController {

    @RequestMapping("hello")
    public String consumer(){
        return "hello consumer";
    }


    @Autowired
    private RestTemplate restTemplate;

    @RequestMapping("{mid}")
    public String findMemberById(@PathVariable Integer mid){

        //通过中间件 发送http请求

        // http://localhost:8080/memeber/mid  发送请求
        String url = "http://localhost:8080/member/" +mid;
        /**
         *
         */
        String resultStr = restTemplate.getForObject(url, String.class);

        // 添加
//        restTemplate.postForObject()

        //删除
//        restTemplate.delete();

        // 修改
//        restTemplate.put();


        return resultStr;
    }

    @RequestMapping("/lb/{mid}")
    public String findMemberById2(@PathVariable Integer mid){
        //通过中间件 发送http请求
        //  String url = "http://微服务的名称/member/"+mid;
        // http://localhost:8080/memeber/mid  发送请求
        String url = "http://MEMBER-SERVER/member/" +mid;
        String resultStr = restTemplate.getForObject(url, String.class);

        return resultStr;
    }
}
